package cn.yunyichina.provider.pay.service.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

import cn.yunyichina.provider.iface.entity.base.*;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import cn.yunyichina.provider.framework.dubbo.service.BaseService;
import cn.yunyichina.provider.framework.utils.UUIDUtil;
import cn.yunyichina.provider.iface.entity.common.Response;
import cn.yunyichina.provider.pay.config.Config;
import cn.yunyichina.provider.pay.constant.MethodRouter;
import cn.yunyichina.provider.pay.dao.PaymentCheckSourceFileDao;
import cn.yunyichina.provider.pay.dao.PaymentJournalDao;
import cn.yunyichina.provider.pay.entity.PaymentCheckSourceFile;
import cn.yunyichina.provider.pay.entity.PaymentJournal;
import cn.yunyichina.provider.pay.service.ThirdFinanceService;
import cn.yunyichina.utils.convert.JsonUtils;

/**
 * 新对账流程优化
 * Created by JoeZ on 2016/11/21.
 */
@Service
public class ThirdFinanceServiceImpl implements ThirdFinanceService {

    private static Logger logger = LoggerFactory.getLogger(ThirdFinanceServiceImpl.class);

    @Autowired
    private PaymentJournalDao paymentJournalDao;

    @Autowired
    private PaymentCheckSourceFileDao paymentCheckSourceFileDao;


    SimpleDateFormat YYYYMMDDHHMISS14 = new SimpleDateFormat("yyyyMMddHHmmss");

    /**
     * 平台与第三方对账
     *
     * @return
     * @info
     */
    @Override
    public JSONObject checkingThirdfinance(String json) {
        logger.info("ThirdFinanceServiceImpl.checkingThirdfinance 开始执行第三方与平台对账流程 json ==>" + JsonUtils.toJsonString(json));
        JSONObject mapReturn = new JSONObject();
        JSONObject maps = JsonUtils.parseObject(json);
        String orgId = maps.getString("orgId");
        String date = maps.getString("date");
        String payMode = maps.getString("payMode");

        mapReturn.putAll(maps);
        mapReturn.put("is_success", true);

        logger.info("<<<<<--开始第三方对账医院：" + orgId);
        PaymentJournal journal = null;
        PaymentCheckSourceFile checkSourceFile = null;
        List<PaymentCheckSourceFile> sources = null;
        List<PaymentJournal> journals = null;
        Map<String, PaymentJournal> journalPlusMap = new HashMap<String, PaymentJournal>();
        Map<String, PaymentJournal> journalMinusMap = new HashMap<String, PaymentJournal>();
        Map<String, PaymentCheckSourceFile> checkSourceFilePlusMap = new HashMap<String, PaymentCheckSourceFile>();
        Map<String, PaymentCheckSourceFile> checkSourceMinusMap = new HashMap<String, PaymentCheckSourceFile>();
        List<PaymentJournal> paymentJournals = new ArrayList<PaymentJournal>();
        Map<String, PaymentJournal> journalTempMap = null;
        Map<String, String> map = null;
        int count = 0;

        try {
            //获取三方支付对账单
            checkSourceFile = new PaymentCheckSourceFile();
            checkSourceFile.setOrgId(orgId);
            checkSourceFile.setBeginPayTime(date + " 00:00:00");
            checkSourceFile.setEndPayTime(date + " 23:59:59");
            if (payMode != null && StringUtils.isNotBlank(payMode)) {
                checkSourceFile.setPayMode(new Short(payMode));
            }
            sources = paymentCheckSourceFileDao.select(checkSourceFile);

            for (PaymentCheckSourceFile source : sources) {
                if (source.getPayStatus() == 1) {
                    checkSourceFilePlusMap.put(source.getOrderNo(), source);
                } else {
                    checkSourceMinusMap.put(source.getOrderNo(), source);
                }
            }

            //获取我方流水表账单
            journal = new PaymentJournal();
            journal.setBeginPayTime(date + " 00:00:00");
            journal.setEndPayTime(date + " 23:59:59");
//            journal.setPayMode(payMode);
//            journal.setPlatformId("3c834c3ea26b11e6951000163e00175d");
            journal.setOrgId(orgId);
            journals = paymentJournalDao.selectjournalsforPaymode(orgId, StringUtils.isBlank(payMode) ? null : new Short(payMode), date, date, journal.getPlatformId());
            for (PaymentJournal paymentJournal : journals) {
                if (StringUtils.contains(paymentJournal.getPayStatus().toString(), "1") || StringUtils.contains(paymentJournal.getPayStatus().toString(), "4")) {
                    journalPlusMap.put(paymentJournal.getOrderNo(), paymentJournal);
                } else if (StringUtils.contains(paymentJournal.getPayStatus().toString(), "2") || StringUtils.contains(paymentJournal.getPayStatus().toString(), "5")) {
                    journalMinusMap.put(paymentJournal.getOrderNo(), paymentJournal);
                }
            }

            String[] orderTypes = null;
            Boolean checkDealIdFlag = false;
            //根据orgId查询org_code
            Response resp = BaseService.callHumpFromInternal(MethodRouter.BASE_FIND_ORG_BY_ID, JsonUtils.toJsonString(orgId));
            Org org = JsonUtils.parseObject(resp.getResult(), Org.class);
            if (org != null) {

                //根据规则配置表sys_rule,判断正交易是否需要对PaymentDealId
                map = new HashMap<String, String>();
                map.put("attribute_name", Config.RULE_ATTRIBUTE_NAME_FOR_CHECKUSEPAYMENTDEALID);
                map.put("org_code", org.getOrgCode());
                resp = BaseService.callHumpFromInternal(MethodRouter.FIND_SYS_RULE_ATTRIBUTE, JSON.toJSONString(map));
                if (StringUtils.isNotBlank(resp.getResult())) {
                    Rule rule = JsonUtils.parseObject(resp.getResult(), Rule.class);
                    if ("0".equals(rule.getAttributeProperties())) {
                        checkDealIdFlag = true;
                    }
                }

                //根据规则配置表sys_rule,判断哪些订单类型不参与对账
                orderTypes = checkOrderRule(org.getOrgCode());
                logger.info("ThirdFinanceServiceImpl.checkingThirdfinance " + org.getOrgName() + "_最终获得不参与对账订单类型：" + Arrays.toString(orderTypes));
            }


            if (orderTypes != null) {
                List<String> delList = new ArrayList<String>();
                //根据规则配置表sys_rule,筛选掉不参与对账订单
                Iterator<String> journalPmaps = journalPlusMap.keySet().iterator();
                while (journalPmaps.hasNext()) {
                    String orderNo = journalPmaps.next().toString();
                    PaymentJournal paymentJournal = journalPlusMap.get(orderNo);
                    boolean contains = ArrayUtils.contains(orderTypes, String.valueOf(paymentJournal.getOrderType()));
                    if (contains) {
                        delList.add(orderNo);
                    }
                }

                for (String delOrderNo : delList) {
                    journalPlusMap.remove(delOrderNo);
                    checkSourceFilePlusMap.remove(delOrderNo);
                }

                delList.clear();
                Iterator<String> journalMmaps = journalMinusMap.keySet().iterator();
                while (journalMmaps.hasNext()) {
                    String orderNo = journalMmaps.next().toString();
                    PaymentJournal paymentJournal = journalMinusMap.get(orderNo);
                    boolean contains = ArrayUtils.contains(orderTypes, String.valueOf(paymentJournal.getOrderType()));
                    if (contains) {
                        delList.add(orderNo);
                    }
                }

                for (String delOrderNo : delList) {
                    journalMinusMap.remove(delOrderNo);
                    checkSourceMinusMap.remove(delOrderNo);
                }
            }


            //处理第三方正交易
            Iterator<String> sIterator = checkSourceFilePlusMap.keySet().iterator();
            journalTempMap = new HashMap<String, PaymentJournal>();
            journalTempMap.putAll(journalPlusMap);
            while (sIterator.hasNext()) {
                String sOrderNo = sIterator.next().toString();
                PaymentCheckSourceFile pSource = checkSourceFilePlusMap.get(sOrderNo);

                if (journalPlusMap.containsKey(sOrderNo)) {
                    PaymentJournal pJournal = journalPlusMap.get(sOrderNo);

//                        //跳过不参与正交易对账订单类型
//                        if(orderTypes != null){
//                            boolean contains = ArrayUtils.contains(orderTypes, String.valueOf(pJournal.getOrderType()));
//                            if(contains){
//                                journalTempMap.remove(sOrderNo);
//                                continue;
//                            }
//                        }

                    if (checkDealIdFlag) {
                        if (pJournal.getPayAmount().intValue() != pSource.getPayAmount().intValue()) {
                            pJournal.setCheckStatus((short) 4);
                            pJournal.setCheckTime(parseDate(date));
                            pJournal.setDescription("对账异常:第三方支付流水金额[" + Double.valueOf(pSource.getPayAmount().intValue()) / 100 + "元]和我方流水金额[" + Double.valueOf(pJournal.getPayAmount().intValue()) / 100 + "元]不一致");
                        } else {
                            pJournal.setCheckTime(parseDate(date));
                            pJournal.setCheckStatus((short) 1);
                        }
                    } else {
                        if (pJournal.getPayAmount().intValue() != pSource.getPayAmount().intValue()) {
                            pJournal.setCheckStatus((short) 4);
                            pJournal.setCheckTime(parseDate(date));
                            pJournal.setDescription("对账异常:第三方支付流水金额[" + Double.valueOf(pSource.getPayAmount().intValue()) / 100 + "元]和我方流水金额[" + Double.valueOf(pJournal.getPayAmount().intValue()) / 100 + "元]不一致");
                        } else if (!pJournal.getPaymentDealId().equals(pSource.getPaymentDealId())) {
                            pJournal.setCheckStatus((short) 4);
                            pJournal.setCheckTime(parseDate(date));
                            pJournal.setDescription("对账异常:第三方支付流水ID[" + pSource.getPaymentDealId() + "]和我方流水ID[" + pJournal.getPaymentDealId() + "]不一致");
                        } else {
                            pJournal.setCheckTime(parseDate(date));
                            pJournal.setCheckStatus((short) 1);
                        }
                    }

                    paymentJournalDao.update(pJournal);
                } else {//平台没有第三方的流水
                    //插入流水表记录
                    journal = new PaymentJournal();
                    journal.setId(UUIDUtil.get32UUID());
                    journal.setPayAppId(pSource.getPayAppId());  //'第三方支付APP_ID'
                    journal.setHisOrderNo("");    //医院交易流水号
                    journal.setOutOrderNo("");    //外部订单号
                    journal.setPaymentDealId(pSource.getPaymentDealId());
                    journal.setPaymentDealNo(String.valueOf(new Date().getTime())); //云医支付流水号 随机生成

                    map = new HashMap<String, String>();
                    map.put("order_no", sOrderNo);
                    Response response = BaseService.callHumpFromInternal(MethodRouter.BASE_FIND_ORDER, JSON.toJSONString(map));
                    OrderExtVo order = null;
                    if ("0".equals(response.getResultCode())) {
                        order = JsonUtils.parseObject(response.getResult(), OrderExtVo.class);
                        int orderType = Integer.parseInt(String.valueOf(order.getOrderType()));
                        journal.setOrderType((short) orderType);
                        journal.setPlatformId(order.getPlatformId());
                        journal.setPlatformName(order.getPlatformName());
                        journal.setPlatformOrgAppCode(order.getPlatformOrgAppCode());
                        journal.setOrgId(order.getOrgId());
                        journal.setOrgName(order.getOrgName());
                        journal.setHisOrderNo(order.getHisOrderNo());
                    } else {
                        journal.setPlatformId(pSource.getPlatformId());
                        journal.setPlatformName(pSource.getPlatformName());
                        journal.setOrgId(pSource.getOrgId()); //'组织ID'
                        journal.setOrgName(pSource.getOrgName()); //'组织名'
                        journal.setOrderType(null);
                    }

                    journal.setOrgCode(pSource.getOrgCode());
                    journal.setPlatformCode(pSource.getPlatformCode());
                    journal.setPlatformOrgAppName(pSource.getPlatformOrgAppName());
                    journal.setPayStatus((short) 4); //交易状态 1=正常  2=退款 3=冲正 4=对账插入（正常）5=对账插入（退款） 6=出错
                    journal.setOrderNo(sOrderNo);
                    journal.setCheckStatus((short) 1);
                    journal.setPayCode("");
                    journal.setDealAccount(pSource.getDealAccount());
                    journal.setAccountName(pSource.getAccountName());
                    journal.setPayAmount(pSource.getPayAmount());
                    journal.setSettlementStatus((short) 0);  //清算状态 0-未清算  1-已清算
                    journal.setAccountAmount(0);    //个账
                    journal.setMedicareAmount(0);   //统筹
                    journal.setInsuranceAmount(0);  //记账合计
                    journal.setTotalAmount(pSource.getPayAmount());  //总金额
                    journal.setSettlementTime(null);    //清算时间
                    journal.setCreatedTime(pSource.getCreatedTime());
                    journal.setPayTime(pSource.getPayTime());
                    journal.setPayMode(pSource.getPayMode());
                    journal.setIsAutoRefund((short) 0);
                    journal.setCheckTime(parseDate(date));
                    paymentJournals.add(journal);

                    //根据payStatus判断order状态
                    if (order.getPayStatus() != 3) {
                        order.setPayTime(journal.getPayTime());
                        order.setPaymentDealId(journal.getPaymentDealId());
                        order.setPayStatus((short) 3);
                        order.setOrderStatus((short) 3);
                        BaseService.callHumpFromInternal(MethodRouter.BASE_UPDATE_ORDER, JsonUtils.toJsonString(order));
                    }
                }
                journalTempMap.remove(sOrderNo);
                count++;
            }


            //处理长款交易，由于存在正、负交易单号相同，所以需要分开处理
            Iterator<String> aIterator = journalTempMap.keySet().iterator();
            while (aIterator.hasNext()) {
                PaymentJournal exJournal = journalTempMap.get(aIterator.next().toString());

                //如果是海慈，就直接对平
                if ("3c834c3ea26b11e6951000163e00175d".equals(exJournal.getPlatformId())) {
                    logger.info("海慈订单：" + exJournal.getOrderNo() + " —— 已对！");
                    exJournal.setCheckStatus((short) 1);
                    exJournal.setCheckTime(parseDate(date));
                } else {
                    exJournal.setCheckStatus((short) 4);
                    exJournal.setPayStatus((short) 6);
                    exJournal.setCheckTime(parseDate(date));
                    exJournal.setDescription("支付交易订单:" + exJournal.getOrderNo() + "第三方支付流水没有，我方流水表有");
                }
                paymentJournalDao.update(exJournal);
            }

            //处理第三方负交易
            Iterator<String> mIterator = checkSourceMinusMap.keySet().iterator();
            journalTempMap = new HashMap<String, PaymentJournal>();
            journalTempMap.putAll(journalMinusMap);
            while (mIterator.hasNext()) {
                String sOrderNo = mIterator.next().toString();
                PaymentCheckSourceFile mSource = checkSourceMinusMap.get(sOrderNo);

                if (journalMinusMap.containsKey(sOrderNo)) {
                    PaymentJournal mJournal = journalMinusMap.get(sOrderNo);

//                    //跳过不参与负交易对账订单类型
//                    if (orderTypes != null) {
//                        boolean contains = ArrayUtils.contains(orderTypes, String.valueOf(mJournal.getOrderType()));
//                        if (contains) {
//                            journalTempMap.remove(sOrderNo);
//                            continue;
//                        }
//                    }


                    if (mJournal.getPayAmount().intValue() != mSource.getPayAmount().intValue()) {
                        mJournal.setCheckStatus((short) 4);
                        mJournal.setCheckTime(parseDate(date));
                        mJournal.setDescription("对账异常:第三方支付流水金额[" + Double.valueOf(mSource.getPayAmount().intValue()) / 100 + "元]和我方流水金额[" + Double.valueOf(mJournal.getPayAmount().intValue()) / 100 + "元]不一致");
                    } else {
                        mJournal.setCheckTime(parseDate(date));
                        mJournal.setCheckStatus((short) 1);
                    }
                    paymentJournalDao.update(mJournal);
                } else {
                    //插入流水表记录
                    journal = new PaymentJournal();
                    journal.setId(UUIDUtil.get32UUID());
                    journal.setPayAppId(mSource.getPayAppId());  //'第三方支付APP_ID'
                    journal.setHisOrderNo("");    //医院交易流水号
                    journal.setOutOrderNo("");    //外部订单号
                    journal.setPaymentDealId(mSource.getPaymentDealId());
                    journal.setPaymentDealNo(String.valueOf(new Date().getTime())); //云医支付流水号 随机生成

                    map = new HashMap<String, String>();
                    map.put("order_no", sOrderNo);
                    Response response = BaseService.callHumpFromInternal(MethodRouter.BASE_FIND_ORDER, JSON.toJSONString(map));
                    OrderExtVo order = null;
                    if ("0".equals(response.getResultCode())) {
                        order = JsonUtils.parseObject(response.getResult(), OrderExtVo.class);
                        int orderType = Integer.parseInt(String.valueOf(order.getOrderType()));
                        journal.setOrderType((short) orderType);
                        journal.setPlatformId(order.getPlatformId());
                        journal.setPlatformName(order.getPlatformName());
                        journal.setPlatformOrgAppCode(order.getPlatformOrgAppCode());
                        journal.setOrgId(order.getOrgId());
                        journal.setOrgName(order.getOrgName());
                        journal.setHisOrderNo(order.getHisOrderNo());
                    } else {
                        journal.setPlatformId(mSource.getPlatformId());
                        journal.setPlatformName(mSource.getPlatformName());
                        journal.setOrgId(mSource.getOrgId()); //'组织ID'
                        journal.setOrgName(mSource.getOrgName()); //'组织名'
                        journal.setOrderType(null);
                    }

                    journal.setOrgCode(mSource.getOrgCode());
                    journal.setPlatformCode(mSource.getPlatformCode());
                    journal.setPlatformOrgAppName(mSource.getPlatformOrgAppName());
                    journal.setPayStatus((short) 5);    //交易状态 1=正常  2=退款 3=冲正 4=对账插入（正常）5=对账插入（退款） 6=出错
                    journal.setOrderNo(sOrderNo);
                    journal.setCheckStatus((short) 1);
                    journal.setPayCode("");
                    journal.setDealAccount(mSource.getDealAccount());
                    journal.setAccountName(mSource.getAccountName());
                    journal.setPayAmount(mSource.getPayAmount());
                    journal.setSettlementStatus((short) 0);  //清算状态 0-未清算  1-已清算
                    journal.setAccountAmount(0);    //个账
                    journal.setMedicareAmount(0);   //统筹
                    journal.setInsuranceAmount(0);  //记账合计
                    journal.setTotalAmount(mSource.getPayAmount());  //总金额
                    journal.setSettlementTime(null);    //清算时间
                    journal.setCreatedTime(mSource.getCreatedTime());
                    journal.setPayTime(mSource.getPayTime());
                    journal.setPayMode(mSource.getPayMode());
                    journal.setIsAutoRefund((short) 0);
                    journal.setCheckTime(parseDate(date));
                    paymentJournals.add(journal);

                    //根据payStatus判断order状态
                    if (order.getPayStatus() != 7) {
                        order.setPayTime(journal.getPayTime());
                        order.setPaymentDealId(journal.getPaymentDealId());
                        order.setPayStatus((short) 7);
                        order.setOrderStatus((short) 7);
                        BaseService.callHumpFromInternal(MethodRouter.BASE_UPDATE_ORDER, JsonUtils.toJsonString(order));
                    }

                }
                journalTempMap.remove(sOrderNo);
                count++;
            }


            Iterator<String> bIterator = journalTempMap.keySet().iterator();
            while (bIterator.hasNext()) {
                PaymentJournal exJournal = journalTempMap.get(bIterator.next().toString());

                //如果是海慈，就直接对平
                if ("3c834c3ea26b11e6951000163e00175d".equals(exJournal.getPlatformId())) {
                    logger.info("海慈订单：" + exJournal.getOrderNo() + " —— 已对！");
                    exJournal.setCheckStatus((short) 1);
                    exJournal.setCheckTime(parseDate(date));
                } else {
                    exJournal.setCheckStatus((short) 4);
                    exJournal.setPayStatus((short) 6);
                    exJournal.setCheckTime(parseDate(date));
                    exJournal.setDescription("退款交易订单:" + exJournal.getOrderNo() + "第三方支付流水没有，我方流水表有");
                }

                paymentJournalDao.update(exJournal);
            }

            if (paymentJournals.size() > 0) {
                paymentJournalDao.batchInsert(paymentJournals);
            }

        } catch (Exception e) {
            mapReturn.put("is_success", false);
            mapReturn.put("checkingThirdfinanceMessage", "第三方对账发生异常" + e.getMessage());
            logger.error("checkingThirdfinance与第三方对账发生异常", e);
            logger.error("[PaymentCheckingImpl.checkingFile]", e);

            //取机构信息
            Map<String, Object> paramOrg = new HashMap<>();
            paramOrg.put("id", orgId);
            JSONObject jsonOrg = JsonUtils.parseObject(BaseService.callHumpFromInternal("yyt.base.org.by.id.find", JsonUtils.toJsonString(paramOrg)).getResult());

            //事件信息
            Map<String, Object> paramEvent = new HashMap<>();
            paramEvent.put("event_code", "CK_PLATFORM_CHECK_PAY");
            paramEvent.put("module_code", "CHECK_ACCOUNT");
            Response responseEvent = BaseService.callHumpFromInternal("yyt.base.event.get", JsonUtils.toJsonString(paramEvent));
            if (StringUtils.isNotBlank(responseEvent.getResult())) {
                EventVo event = JsonUtils.parseObject(responseEvent.getResult(), EventVo.class);
                FinanceServiceImpl.sendSmsForFail(orgId, "CK_PLATFORM_CHECK_PAY", jsonOrg.getString("org_name"), date, YYYYMMDDHHMISS14.format(new Date()), event.getEventLevel() + "", "第三方对账发生异常" + e.getMessage());
            } else {
                logger.error("获取系统事件定义事事件，无法获取事件级别：CK_PLATFORM_CHECK_PAY");
                FinanceServiceImpl.sendSmsForFail(orgId, "CK_PLATFORM_CHECK_PAY", jsonOrg.getString("org_name"), date, YYYYMMDDHHMISS14.format(new Date()), "-1", "第三方对账发生异常" + e.getMessage());
            }

            FinanceServiceImpl.insertLog(orgId, "CK_PLATFORM_CHECK_PAY", JsonUtils.toJsonString(mapReturn));

        }
        mapReturn.put("count", count);
        return mapReturn;
    }


    /**
     * 根据规则判断该机构下订单是否参与对账
     *
     * @param orgCode
     * @return
     */
    public String[] checkOrderRule(String orgCode) {
        String[] noCheckOrderType = null;
        Map<String, String> map = new HashMap<>();
        map.put("attribute_name", Config.RULE_ATTRIBUTE_NAME_FOR_CHECKORDERTYPE);
        map.put("org_code", orgCode);
        Response response = BaseService.callHumpFromInternal(MethodRouter.FIND_SYS_RULE_ATTRIBUTE, JSON.toJSONString(map));
        if (StringUtils.isNotBlank(response.getResult())) {
            Rule rule = JsonUtils.parseObject(response.getResult(), Rule.class);
            String properties = rule.getAttributeProperties();
            noCheckOrderType = properties.split(";");
        }

        return noCheckOrderType;
    }


    /**
     * 获取后一天时间并且取当前日期
     *
     * @param date
     * @return
     */
    public String parseDate(String date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat sd = new SimpleDateFormat("HH:mm:ss");
        Date dt = null;
        try {
            dt = sdf.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar rightNow = Calendar.getInstance();
        rightNow.setTime(dt);
        rightNow.add(Calendar.DAY_OF_YEAR, 1);
        String checkTime = sdf.format(rightNow.getTime());

        return checkTime + " " + sd.format(new Date());
    }


    public static boolean useArraysBinarySearch(String[] arr, String targetValue) {
        int a = Arrays.binarySearch(arr, targetValue);
        if (a > 0)
            return true;
        else
            return false;
    }

    public static void main(String[] args) {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        ThirdFinanceServiceImpl bean = applicationContext.getBean(ThirdFinanceServiceImpl.class);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("orgId", "f670fef3acbc11e6990400163e0042e6");
        jsonObject.put("date", "2017-12-27");
//        jsonObject.put("payMode" , "1");
        bean.checkingThirdfinance(JsonUtils.toJsonString(jsonObject));
    }
}
